﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.popups.adopt {
    import reprise.ui.*;
    import flash.events.*;
    import flash.display.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.views.popups.*;
    import net.wooga.pets.models.world.vos.actors.*;
    import net.wooga.pets.views.components.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;
    import net.wooga.pets.external.*;

    public class HappyFamilyPopupMediator extends AbstractPopupMediator {

        private const CSS_CLASS_FATHER:String = "dad";
        private const CSS_CLASS_MOTHER:String = "mom";

        public var friendsModel:FriendsModel;
        public var tickModel:TickModel;
        private var _babyVO:BabyVO;

        override public function onRegister():void{
            super.onRegister();
            this.tickModel.pause = true;
            this._babyVO = BabyVO(this.view.data);
            RepriseUtils.addComponent(this.view, "image");
            var _local1:ClipComponent = RepriseUtils.addClipComponent(this.view, "baby", AssetsLibrary.getMovieClip("RC_HappyFamilyBabyImages"));
            MovieClip(_local1.clip).gotoAndStop(this._babyVO.type);
            l(("goto baby: " + this._babyVO.type));
            addLabel("title showcardGothicFont", "kindergarten_popup_happy_family_header");
            addLabel("subline myriadProFontNormal", "kindergarten_popup_happy_family_thanks");
            addOkButton("global_button_share", this.view);
            this.createParent(this._babyVO.dadId, this.CSS_CLASS_FATHER);
            this.createParent(this._babyVO.momId, this.CSS_CLASS_MOTHER);
            var _local2:ClipComponent = RepriseUtils.addClipComponent(this.view, "starAnimationDisplay", AssetsLibrary.getMovieClip("RC_HappyFamilyStarAnimation"));
            MovieClip(_local2.clip).mouseChildren = (MovieClip(_local2.clip).mouseEnabled = false);
        }
        private function createParent(_arg1:String, _arg2:String):void{
            var _local3:String;
            var _local4:String;
            var _local7:MovieClip;
            var _local8:int;
            var _local9:FacebookImageResource;
            var _local5:UIComponent = RepriseUtils.addComponent(this.view, "scrollItemBackground");
            _local5.addCSSClass(_arg2);
            var _local6:UIComponent = RepriseUtils.addComponent(_local5, "imageDisplay");
            if (_arg1 == GameConstants.KARLA_FACEBOOK_ID){
                _local7 = AssetsLibrary.getMovieClip("RC_ImageBackground");
                AssetsLibrary.getMovieClip("RC_ImageBackground").x = (_local7.x - 2);
                _local7.gotoAndStop(_arg2);
                RepriseUtils.addClipComponent(_local6, "parentsImage", _local7);
                _local4 = this.getNameByGender(_arg2);
            } else {
                _local8 = 0;
                while (_local8 < this.friendsModel.friends.length) {
                    if (this.friendsModel.friends[_local8].uid == _arg1){
                        _local3 = this.friendsModel.friends[_local8].picture;
                        _local4 = this.friendsModel.friends[_local8].first_name;
                        break;
                    };
                    _local8++;
                };
                _local9 = new FacebookImageResource(_local3);
                _local9.addEventListener(Event.COMPLETE, this.imageResourceComplete);
                _local9.execute();
                RepriseUtils.addClipComponent(_local6, "parentsImage", _local9.loader());
            };
            RepriseUtils.addLabel(_local5, "nameLabel", _local4);
        }
        private function getNameByGender(_arg1:String):String{
            var _local2:String;
            if (_arg1 == this.CSS_CLASS_FATHER){
                _local2 = language.getTextByKey("kindergarten_godfather");
            } else {
                if (_arg1 == this.CSS_CLASS_MOTHER){
                    _local2 = language.getTextByKey("kindergarten_godmother");
                };
            };
            return (_local2);
        }
        private function imageResourceComplete(_arg1:Event):void{
            var _local2:FacebookImageResource = FacebookImageResource(_arg1.target);
            _local2.removeEventListener(Event.COMPLETE, this.imageResourceComplete);
        }
        private function get view():HappyFamilyPopupView{
            return ((viewComponent as HappyFamilyPopupView));
        }
        override protected function onOk(_arg1:MouseEvent):void{
            super.onOk(_arg1);
            dispatch(new InfoEvent(EventConstants.POST_ON_WALL, null, {type:GameConstants.POST_HAPPY_FAMILY, data:this._babyVO}));
        }
        override protected function close():void{
            this.tickModel.pause = false;
            dispatch(new Event(EventConstants.BUBBLE_CLOSED));
            var _local1:InfoEvent = new InfoEvent(EventConstants.DESTROY_POPUP, null, this.view);
            dispatch(_local1);
            dispatch(new InfoEvent(EventConstants.BABY_TREATMENTS_FINISHED, null, this._babyVO));
        }

    }
}//package net.wooga.pets.views.popups.adopt 
